package com.neusoft.yuejian_01.model;

import com.neusoft.yuejian_01.base.BaseModel;
import com.neusoft.yuejian_01.javabean.CollectBean;
import com.neusoft.yuejian_01.javabean.IsCollectBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.service.CollectService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by MARIA on 2017/10/21.
 */

public class CollectModel extends BaseModel {
    //判断是否收藏
    public void ifCollected(String u_id, String select_id, String flag,final RetrofitListener listener) {
        this.flag = Const.IfCollect;
        CollectService collectService=retrofit.create( CollectService.class);
        Call call = collectService.ifCollected(u_id,select_id,flag);
        call.enqueue(new Callback<IsCollectBean>() {
            @Override
            public void onResponse(Call<IsCollectBean> call, Response<IsCollectBean> response) {
                IsCollectBean isCollectBean=response.body();
                listener.onSuccess(isCollectBean,Const.IfCollect);
            }
            @Override
            public void onFailure(Call<IsCollectBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //用户收藏帖子
    public void doCollect(int u_id, String p_id,final RetrofitListener listener) {
        this.flag = Const.DoCollect;
        CollectService collectService=retrofit.create( CollectService.class);
        Call call = collectService.doCollect(u_id,p_id);
        call.enqueue(new Callback<CollectBean>() {
            @Override
            public void onResponse(Call<CollectBean> call, Response<CollectBean> response) {
                CollectBean collectBean=response.body();
                listener.onSuccess(collectBean,flag);
            }
            @Override
            public void onFailure(Call<CollectBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
